{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "premier-galaxy",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abc\" < \"bcd\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "functioning-irish",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"abc\" < \"abc\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "straight-marketing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"art zero\" < \"own kit dig\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "lined-microwave",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"own kit dig\" > \"art zero\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "legal-species",
   "metadata": {},
   "outputs": [],
   "source": [
    "import string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "funded-responsibility",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string.ascii_letters.index(\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "front-jesus",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/reorder-data-in-log-files/\n",
    "\n",
    "\n",
    "Runtime: 40 ms, faster than 41.53% of Python3 online submissions for Reorder Data in Log Files.\n",
    "Memory Usage: 14.4 MB, less than 67.16% of Python3 online submissions for Reorder Data in Log Files.\n",
    "\n",
    "\n",
    "```python\n",
    "import string\n",
    "import functools\n",
    "\n",
    "def sort_function(the_tuple1, the_tuple2):\n",
    "    a = \"\".join(the_tuple1[1])\n",
    "    b = \"\".join(the_tuple2[1])\n",
    "    if (a == b):\n",
    "        a = \"\".join(the_tuple1[0])\n",
    "        b = \"\".join(the_tuple2[0])\n",
    "        return b > a\n",
    "    return a < b\n",
    "    \n",
    "class Solution:\n",
    "    def reorderLogFiles(self, logs: List[str]) -> List[str]:\n",
    "        #6:11\n",
    "        digits_list = []\n",
    "        letters_list = []\n",
    "        for log in logs:\n",
    "            splits = log.split(\" \")\n",
    "            identifier = splits[0:1]\n",
    "            contents = splits[1:]\n",
    "            if all([c.isdigit() for c in contents]):\n",
    "                digits_list.append((identifier, contents))\n",
    "            else:\n",
    "                letters_list.append((identifier, contents))\n",
    "        #letters_list.sort(key=functools.cmp_to_key(sort_function))\n",
    "        letters_list.sort(key=lambda t: (t[1], t[0]))\n",
    "        results = []\n",
    "        for each in letters_list+digits_list:\n",
    "            results.append(\" \".join(each[0] + each[1]))\n",
    "        return results\n",
    "        #6:56\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "advance-conditioning",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
